{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm add-new" type="button">+ 添加办公工具</button>
  </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
	<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table, tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#test'
			,toolbar: '#toolbarDemo'
			,defaultToolbar: false
			,title:'办公工具列表'
			,url: "/home/cate/links"
			,page: false
			,cellMinWidth: 80
			,cols: [[
					{field:'id',width:80, title: 'ID号', align:'center'}
					,{field:'title',title: '书签名称',width:300}
					,{field:'url',title: '链接地址'}
					,{field:'target', title: '是否新窗口打开',width:120,align:'center',templet: function(d){
						var html1='<span class="green">是</span>';
						var html2='<span class="yellow">否</span>';
						if(d.target==1){
							return html1;
						}
						else{
							return html2;
						}
					}}
					,{field:'sort',title: '排序',width:100,align:'center'}
					,{width:100,title: '操作', align:'center',templet: function(d){
						var html='';
						var btn='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
						var btn1='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
						html = '<div class="layui-btn-group">'+btn+btn1+'</div>';
						return html;
					}}
				]]
			});
			
			table.on('tool(test)',function (obj) {
				if(obj.event === 'edit'){					
					tool.side('/home/cate/links_add/id/'+obj.data.id);
				}
				if(obj.event === 'del'){
					layer.confirm('确定要删除该办公工具吗?', {icon: 3, title:'提示'}, function(index){
						let callback = function (e) {
							layer.msg(e.msg);
							if (e.code == 0) {
								layui.pageTable.reload();
							}
						}
						tool.post("/home/cate/links_del", { id: obj.data.id,status: 1}, callback);
						layer.close(index);
					});
				}
			});
			
			$('body').on('click','.add-new',function(){
				tool.side('/home/cate/links_add');
			});
		}
	</script>
{/block}
<!-- /脚本 -->